using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JGSY.CMS.LowCode.Platform.Domain.Interfaces;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 产品管理实体
    /// 对应 products 表，支持JSON属性和媒体资源
    /// </summary>
    [Table("products")]
    public class Product : ITenantEntity
    {
        /// <summary>
        /// 租户ID
        /// </summary>
        [Required]
        [StringLength(36)]
        [Column("tenant_id")]
        public string TenantId { get; set; } = string.Empty;

        /// <summary>
        /// 主键ID
        /// </summary>
        [Key]
        public long Id { get; set; }

        /// <summary>
        /// 产品名称
        /// </summary>
        [Required]
        [StringLength(255)]
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 产品别名/URL slug
        /// </summary>
        [StringLength(255)]
        public string? Slug { get; set; }

        /// <summary>
        /// 产品型号
        /// </summary>
        [StringLength(255)]
        public string? Model { get; set; }

        /// <summary>
        /// 产品SKU编码
        /// </summary>
        [StringLength(100)]
        public string? Sku { get; set; }

        /// <summary>
        /// 产品价格
        /// </summary>
        [Column(TypeName = "decimal(10,2)")]
        public decimal Price { get; set; }

        /// <summary>
        /// 原价（用于显示折扣）
        /// </summary>
        [Column(TypeName = "decimal(10,2)")]
        public decimal? OriginalPrice { get; set; }

        /// <summary>
        /// 成本价
        /// </summary>
        [Column(TypeName = "decimal(10,2)")]
        public decimal? CostPrice { get; set; }

        /// <summary>
        /// 产品简介
        /// </summary>
        [StringLength(500)]
        public string? Summary { get; set; }

        /// <summary>
        /// 产品描述
        /// </summary>
        [Column(TypeName = "text")]
        public string? Description { get; set; }

        /// <summary>
        /// 分类ID
        /// </summary>
        public long? CategoryId { get; set; }

        /// <summary>
        /// 品牌
        /// </summary>
        [StringLength(100)]
        public string? Brand { get; set; }

        /// <summary>
        /// 标签列表（JSON格式）
        /// </summary>
        [Column(TypeName = "json")]
        public string? Tags { get; set; }

        /// <summary>
        /// 产品属性（如规格等）
        /// JSON格式存储
        /// </summary>
        [Column(TypeName = "json")]
        public string? Attributes { get; set; }

        /// <summary>
        /// 产品图片列表
        /// JSON格式存储图片URL数组
        /// </summary>
        [Column(TypeName = "json")]
        public string? Images { get; set; }

        /// <summary>
        /// 产品视频列表
        /// JSON格式存储视频URL数组
        /// </summary>
        [Column(TypeName = "json")]
        public string? Videos { get; set; }

        /// <summary>
        /// 库存数量
        /// </summary>
        public int Stock { get; set; }

        /// <summary>
        /// 库存预警值
        /// </summary>
        public int? StockAlert { get; set; }

        /// <summary>
        /// 产品重量（克）
        /// </summary>
        public int? Weight { get; set; }

        /// <summary>
        /// 产品尺寸（JSON格式：长宽高）
        /// </summary>
        [Column(TypeName = "json")]
        public string? Dimensions { get; set; }

        /// <summary>
        /// 销量
        /// </summary>
        public int SalesCount { get; set; } = 0;

        /// <summary>
        /// 浏览量
        /// </summary>
        public int ViewCount { get; set; } = 0;

        /// <summary>
        /// 收藏数
        /// </summary>
        public int FavoriteCount { get; set; } = 0;

        /// <summary>
        /// 评分（1-5星）
        /// </summary>
        [Column(TypeName = "decimal(2,1)")]
        public decimal? Rating { get; set; }

        /// <summary>
        /// 评论数
        /// </summary>
        public int ReviewCount { get; set; } = 0;

        /// <summary>
        /// 是否推荐
        /// </summary>
        public bool IsRecommended { get; set; } = false;

        /// <summary>
        /// 是否新品
        /// </summary>
        public bool IsNew { get; set; } = false;

        /// <summary>
        /// 是否热销
        /// </summary>
        public bool IsHot { get; set; } = false;

        /// <summary>
        /// 排序权重
        /// </summary>
        public int SortOrder { get; set; } = 0;

        /// <summary>
        /// SEO标题
        /// </summary>
        [StringLength(255)]
        public string? SeoTitle { get; set; }

        /// <summary>
        /// SEO关键词
        /// </summary>
        [StringLength(500)]
        public string? SeoKeywords { get; set; }

        /// <summary>
        /// SEO描述
        /// </summary>
        [StringLength(500)]
        public string? SeoDescription { get; set; }

        /// <summary>
        /// 状态（上架/下架）
        /// 0=下架, 1=上架, 2=预售, 3=售罄
        /// </summary>
        public byte Status { get; set; }

        /// <summary>
        /// 版本号
        /// </summary>
        public int Version { get; set; } = 1;

        /// <summary>
        /// 创建人
        /// </summary>
        [Required]
        public long CreatedBy { get; set; }

        /// <summary>
        /// 修改人
        /// </summary>
        public long? UpdatedBy { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;

        /// <summary>
        /// 创建人导航属性
        /// </summary>
        [ForeignKey(nameof(CreatedBy))]
        public User? Creator { get; set; }

        /// <summary>
        /// 修改人导航属性
        /// </summary>
        [ForeignKey(nameof(UpdatedBy))]
        public User? Updater { get; set; }

        /// <summary>
        /// 租户导航属性
        /// </summary>
        public Tenant? Tenant { get; set; }
    }
}
